package com.feixiang.fxaicodemother.service;

import com.feixiang.fxaicodemother.model.dto.chathistory.ChatHistoryQueryRequest;
import com.feixiang.fxaicodemother.model.enity.User;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.service.IService;
import com.feixiang.fxaicodemother.model.enity.ChatHistory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;

import java.time.LocalDateTime;

/**
 * 对话历史 服务层。
 *
 * @author 飞翔
 */
public interface ChatHistoryService extends IService<ChatHistory> {
    /**
     * 添加对话消息历史
     * @param appId
     * @param message
     * @param messageType
     * @param userId
     * @return
     */
    boolean addChatMessage(Long appId, String message, String messageType,Long userId);
    /**
     * 根据应用id删除对话消息
     * @param appId
     */
    boolean deleteByAppId(Long appId);

    /**
     * 分页查询某一app的对话消息
     * @param appId
     * @param pageSize
     * @param lastCreateTime
     * @param loginUser
     * @return
     */
    Page<ChatHistory> listAppChatHistoryByPage(Long appId, int pageSize,
                                               LocalDateTime lastCreateTime,
                                               User loginUser);

    /**
     *  包装查询条件
     * @param chatHistoryQueryRequest
     * @return
     */
    QueryWrapper getQueryWrapper(ChatHistoryQueryRequest chatHistoryQueryRequest);

    /**
     * 加载对话历史到内存
     * @param appId 应用id
     * @param chatMemory 对话记忆
     * @param maxCount 最大数量
     * @return
     */
    int loadChatHistoryToMemory(Long appId, MessageWindowChatMemory chatMemory, int maxCount);
}
